package com.zhifei.web.job;

import com.zhifei.common.utils.DateUtils;
import com.zhifei.system.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class EmployeeJob {

    @Autowired
    private FxxkService fxxkService;
    @Autowired
    private HlyService hlyService;
    @Autowired
    private JdService jdService;
    @Autowired
    private EmployeeArchivesService employeeArchivesService;
    @Autowired
    private PersonProjectService personProjectService;
    @Autowired
    private DingUserArchivesService dingUserArchivesService;

    @Scheduled(cron = "0 0 0/3 * * ?")
    public void caclOrderProduct(){
        log.info("自动任务------纷享销客订单产品明细数据抓取------");
        try {
            fxxkService.listOrderProduct();
        } catch (Exception e){
            log.error("自动任务--纷享销客订单产品明细数据抓取失败",e);
        }
    }

    @Scheduled(cron = "0 0 0/3 * * ?")
    public void caclOrder(){
        log.info("自动任务------纷享销客项目制人力订单数据抓取------");
        try {
            fxxkService.listOrder();
        } catch (Exception e){
            log.error("自动任务--纷享销客项目制人力订单数据抓取失败",e);
        }
    }

    @Scheduled(cron = "0 0 0/3 * * ?")
    public void caclDevOrder(){
        log.info("自动任务------纷享销客定制开发订单数据抓取------");
        try {
            fxxkService.listDevOrder();
        } catch (Exception e){
            log.error("自动任务--纷享销客定制开发订单数据抓取失败",e);
        }
    }

    @Scheduled(cron = "0 0 0/3 * * ?")
    public void caclRecruitCommission(){
        log.info("自动任务------计算项目制人力招聘提成------");
        try {
            personProjectService.calc();
        } catch (Exception e){
            log.error("自动任务--计算项目制人力招聘提成失败",e);
        }
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    public void listVendor(){
        log.info("自动任务------汇联易供应商数据抓取------");
        try {
            hlyService.listVendor();
        } catch (Exception e){
            log.error("自动任务--汇联易供应商数据抓取失败",e);
        }
    }

    @Scheduled(cron = "0 0 0 ? * 6")
    public void listOtherApOrder(){
        log.info("自动任务------金蝶差旅数据抓取------");
        try {
            jdService.listOtherApOrder();
        } catch (Exception e){
            log.error("自动任务--金蝶差旅数据抓取抓取失败",e);
        }
    }

    @Scheduled(cron = "0 0 0 ? * 6")
    public void listReceiveBill(){
        log.info("自动任务------金蝶回款数据抓取------");
        try {
            jdService.listReceiveBill();
        } catch (Exception e){
            log.error("自动任务--金蝶回款数据抓取失败",e);
        }
    }

    @Scheduled(cron = "0 55 23 L * ?")
    public void generateArchives(){
        log.info("自动任务------生成外派人员每月档案------");
        try {
            Date firstDayOfNowMonth = DateUtils.getFirstDayOfNowMonth();
            Date lastDayOfNowMonth = DateUtils.getLastDayOfNowMonth();
            employeeArchivesService.generateArchives(firstDayOfNowMonth,lastDayOfNowMonth);
        } catch (Exception e){
            log.error("自动任务--生成外派人员每月档案失败",e);
        }
    }

    @Scheduled(cron = "0 55 23 L * ?")
    public void generateUserArchives(){
        log.info("自动任务------生成项目制人力人员每月档案------");
        try {
            Date firstDayOfNowMonth = DateUtils.getFirstDayOfNowMonth();
            Date lastDayOfNowMonth = DateUtils.getLastDayOfNowMonth();
            dingUserArchivesService.generateArchives(firstDayOfNowMonth,lastDayOfNowMonth);
        } catch (Exception e){
            log.error("自动任务--生成项目制人力人员每月档案失败",e);
        }
    }

}
